const WeLengthwaysShaders = `
czm_material czm_getMaterial(czm_materialInput materialInput) {
    czm_material material = czm_getDefaultMaterial(materialInput);
    vec2 st = materialInput.st;
    float filterMin = Weget_lengthWaysFilterMin();
    float filterMax = Weget_lengthWaysFilterMax();
    float minValue = Weget_minValue();
    float maxValue = Weget_maxValue();
    bool shouldClamp = Weget_clamp() > 0.0;
    bool shouldFlipY = Weget_shouldFlipY() > 0.0;
    float lengthwaysAlpha = Weget_lengthwaysAlpha();
    vec4 localExtent = Weget_localExtent();
    vec4 worldExtent = Weget_extent();
    float sumarize = Weget_sumarize();

    vec2 stPoint = Weget_stPoint();
    vec2 edPoint = Weget_edPoint();

    vec2 stUV = WeGetImageryLocalUV(stPoint,worldExtent);
    vec2 edUV = WeGetImageryLocalUV(edPoint,worldExtent);

    float length = st.x;
    vec3 texcoord = vec3(0.0,0.0,st.y);
    texcoord.xy = stUV + (edUV - stUV) * length;

    if(shouldFlipY){
        texcoord.y = 1.0 - texcoord.y;
    }

    float value = WeDecodeValue(texcoord);

    if(sumarize == 1.0) // X
    {
        float width = (worldExtent.z - worldExtent.x);
        float width0 = (localExtent.z - localExtent.x) / width;
        float startX = (localExtent.x - worldExtent.x) / width;
        for(float i=0.0;i<1.0;i+=0.01)
        {
            vec3 str = vec3(startX + i * width0,texcoord.yz);
            float value2 = WeDecodeValue(str);
            if(value2 > value)
            {
                value = value2;
            }
        }
    }
    else if(sumarize == 2.0) // Y
    {
        float height = (worldExtent.w - worldExtent.y);
        float width0 = (localExtent.w - localExtent.y) / height;
        float startX = (localExtent.y - worldExtent.y) / height;
        for(float i=0.0;i<1.0;i+=0.01)
        {
            vec3 str = vec3(texcoord.x,startX + i * width0,texcoord.z);
            if(shouldFlipY){
                str.y = 1.0 - str.y;
            }
            float value2 = WeDecodeValue(str);
            if(value2 > value)
            {
                value = value2;
            }
        }
    }

    float i = abs((value - minValue) / (maxValue - minValue));
    vec4 color = texture(u_TFTexture,vec2(i,0.0));
    if(shouldClamp){
        color.rgb = WeGetRampColor(color.rgb,u_TFTexture,value,minValue,maxValue);
    }

    material.diffuse = color.rgb;
    material.alpha = color.a * (WeIsNodata(value,minValue,filterMin,filterMax) ? 0.0 : lengthwaysAlpha);
    material.specular = 0.0; // Specular mountain tops
    material.shininess = 0.0; // Sharpen highlight
    if(material.alpha == 0.0) discard;
    return material;
}
`;


export default WeLengthwaysShaders;
